﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IHISCETeim.DAL;
using IHISCETeim.Model;
using IHISCETeim.Library;
using System.Data;


namespace IHISCETeim.BLL
{
    /// <summary>
    /// 4.销售类型配置表(FTradeSaleTypeConfig)
    /// </summary>
    public class FTradeSaleTypeConfigController : BaseController
    {
         /// <summary>
        /// 获取所有的销售类型配置表信息
        /// </summary>
        /// <returns></returns>
        public static List<FTradeSaleTypeConfigInfo> GetAll()
        {
            return CBO.FillCollection<FTradeSaleTypeConfigInfo>( FTradeSaleTypeConfigDAL.GetAll());
        }
        /// <summary>
        /// 根据名称获取其详细
        /// </summary>
        /// <param name="XiaoShouLeiXing"></param>
        /// <returns></returns>
        public static FTradeSaleTypeConfigInfo GetByName(string XiaoShouLeiXing)
        {
            try
            {
                List<FTradeSaleTypeConfigInfo> list = GetAll();
                return list.Single(e => e.XiaoShouLeiXing.Trim().ToLower() == XiaoShouLeiXing.Trim().ToLower());
            }
            catch
            {
                return new FTradeSaleTypeConfigInfo();
            }
        }
        /// <summary>
        /// 是否能更改销售类型
        /// </summary>
        /// <param name="oldLeiXing"></param>
        /// <param name="newLeiXing"></param>
        /// <returns></returns>
        public static bool CanChangeXiaoShouLeiXing(string oldLeiXing, string newLeiXing)
        {
            FTradeSaleTypeConfigInfo oldObj = GetByName(oldLeiXing);
            string oldChangeXiaoShuoLeiXing = oldObj.ChangeXiaoShouLeiXing;
            //如果为空，则表示没限制
            return string.IsNullOrEmpty(oldChangeXiaoShuoLeiXing) ? true : oldChangeXiaoShuoLeiXing.IndexOf(newLeiXing) >= 0;
           // return;
        }
        /// <summary>
        /// 是否可缓期操作
        /// </summary>
        /// <param name="LeiXing"></param>
        /// <returns></returns>
        public static bool CanSuspendedMark(string LeiXing)
        {
            FTradeSaleTypeConfigInfo oldObj = GetByName(LeiXing);
            return oldObj.CanSuspendedMark;
        }
    }
}
